home *** CD-ROM | disk | FTP | other *** search
- Path: li.net!jeremy
- From: jeremy@newshost.li.net (Jeremy Markman)
- Newsgroups: comp.lang.c++
- Subject: Re: Is this a memory leak?
- Date: 4 Apr 1996 17:32:58 GMT
- Organization: LI Net (Long Island Network)
- Message-ID: <4k114a$m5d@linet06.li.net>
- References: <4jv214$gv7@insosf1.netins.net>
- NNTP-Posting-Host: linet04.li.net
- X-Newsreader: TIN [version 1.2 PL2]
-
- Harold Howe (hhowe@trgnet.com) wrote:
- : Could someone please tell me if this code leaks memory
-
-
- : public:
- : TopClass::TopClass() { bury = new BuriedClass();}
- : shutDown { bury = 0;}
- : ~TopClass { delete bury}
-
- : Is the memory that was alloced for the buried class lost? If not please
- : describe how it was freed. Does zeroing the pointer free the memory? The
- : delete is a waste of time on a zeroed pointer, isn't it.
-
- Yes, your are correct. By assigning bury to 0, you are effectively
- reassigning the memory pointer to NULL. Therefore, deleting bury has no
- effect. The shutdown function is not necessary, in fact, it is bad
- practice to do that. Just the delete bury is necessary, and if you do
- want to assign 0 to a pointer, use NULL.
-
- More explanation:
- new allocattes memory and delete deallocates it. If you change the
- pointer to that it does not point to the allocated memory, it can't
- deallocate it, now can it?
-
- Hope this helps...
-